home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / util / sys / InstallerNG.lha / InstallerNG / examples / descent.installer next >
Text File  |  2000-10-01  |  2KB  |  88 lines

  1.  
  2. ; this needs the InstallerNG!
  3. (if (not @installer-ng-version)
  4.     (abort "This script needs the InstallerNG by Jens Tröger")
  5. )
  6.  
  7. ; inform the user
  8. (message "This example shows, how to recursively descent into a directory "
  9.          "tree and performing an action on every file or sub-directory.\n\n"
  10.          "Additionally this script demonstrates, how to append \".mp3\" to every filename, "
  11.          "which misses this postfix"
  12. )
  13.  
  14. (swing
  15.   ; ask for the root directory
  16.   (set #rootdir (askdir (prompt "Please select the root directory,\nfrom where the InstallerNG should descent!")
  17.                         (help "")
  18.                         (default "WORK:")
  19.                 )
  20.   )
  21.  
  22.   ; ask for maximal supported filename length
  23.   (set #maxlen (asknumber (prompt "What is the maximal length of a filename,\nsupported by your filesystem?")
  24.                           (help "")
  25.                           (default 31)
  26.                )
  27.   )
  28.  
  29.   ; ask for confirmation to start
  30.   (message "Done?")
  31. )
  32.  
  33. ; now rename all the files!
  34. (working "Now adding \".mp3\" to all the files...")
  35. (P_renameDir #rootdir)
  36.  
  37. ; and done with the job...
  38. (exit (quiet))
  39. (welcome)
  40.  
  41. ; the procedure, which renames all files and descends recursively
  42. ; into the directories
  43. (procedure P_renameDir #d
  44.  
  45.   (debug (cat "DIRECTORY: " #d))
  46.  
  47.   ; create a new environment and walk through the directory
  48.   (let (set #dir #d)
  49.        (
  50.          (foreach #dir "#?" (
  51.                               ; for a file, call the file-handling procedure
  52.                               (if (< @each-type 0) (P_renameFile #dir @each-name))
  53.  
  54.                               ; descent into a sub-directory
  55.                               (if (> @each-type 0) (P_renameDir (tackon #dir @each-name)))
  56.  
  57.                             )
  58.          )
  59.        )
  60.   )
  61. )
  62.  
  63. ; rename a file
  64. (procedure P_renameFile #d #f
  65.  
  66.   ; create a new environment
  67.   (let (set #dir #d #file #f)
  68.  
  69.     ; is the end of this filename ".mp3" ??
  70.     (if (= ".mp3" (substr #file (- (strlen #file) 4)))
  71.  
  72.         ; yes
  73.         (debug (cat "\t" #file " ... skipped"))
  74.  
  75.         ; no - append the ".mp3" (respect the maximal length of a filename
  76.         ;      supported by the filesystem!
  77.         (
  78.           (rename (tackon #dir #file) (tackon #dir (cat (substr #file 0 (- #maxlen 4)) ".mp3")) (safe))
  79.           (debug (cat "\t" #file " ... renamed"))
  80.         )
  81.     )
  82.   )
  83. )
  84.  
  85.  
  86.  
  87.  
  88.